package dj.engine.screen;

import java.util.ArrayList;
import java.util.Collection;

import dj.engine.panel.Panel;
import dj.engine.util.Vec2f;
import dj.engine.util.Vec2i;

public class ProportionalLayout extends AbstractLayoutManager {

	public static final int FIXED_PROPORTIONS = 1<<0; 
	private Collection<ProportionalEntry<Panel>> panels;
	public ProportionalLayout()
	{
		panels = new ArrayList<ProportionalEntry<Panel>>(); 
	}
	
	private class ProportionalEntry<T>
	{
		final T item;
		final float proportionFromSide;
		final float proportionFromTop;
		
		ProportionalEntry(T item, float pSide, float pTop)
		{
			this.item = item;
			this.proportionFromSide = pSide;
			this.proportionFromTop = pTop;
		}
	}
	
	
	
	@Override
	public void add(Panel p) {
		// TODO Auto-generated method stub
		throw new UnsupportedOperationException("add with no options and params");
	}

	@Override
	public void add(Panel p, int options) {
		// TODO Auto-generated method stub
		throw new UnsupportedOperationException("add with no params");
	}
	
	@Override
	public void add(Panel p, int options, Object... params) {
		// TODO Auto-generated method stub
		if(isSet(FIXED_PROPORTIONS, options))
		{
			assert(params.length >= 2 && params[0] instanceof Float && params[1] instanceof Float);
			float pSide = ((Float)params[0]).floatValue();
			float pTop = ((Float)params[1]).floatValue();
			panels.add(new ProportionalEntry<Panel>(p, pSide, pTop));
		}
	}

	@Override
	public void onResize(Vec2i newSize) {
		// TODO Auto-generated method stub
		for(ProportionalEntry<Panel> pe: panels)
		{
			pe.item.setPosition(new Vec2f(newSize.x * pe.proportionFromSide, newSize.y*pe.proportionFromTop));
		}
	}

	
}
